package com.example.springcache;

import com.example.springcache.entity.repository.BookRepository;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * @ClassName AppRunner
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2020/4/26 4:48 PM
 * @Version 1.0
 */
@AllArgsConstructor
@Component
public class AppRunner implements CommandLineRunner {

	private static final Logger log = LoggerFactory.getLogger(AppRunner.class);
	private final BookRepository bookRepository;
	@Override
	public void run(String... args) throws Exception {

		StopWatch clock = new StopWatch();
		log.info(".... Fetching books");
		clock.start("书：1234");
		log.info("isbn-1234 -->" + bookRepository.getByIsbn("isbn-1234"));
		clock.stop();
		clock.start("书：4567");
		log.info("isbn-4567 -->" + bookRepository.getByIsbn("isbn-4567"));
		clock.stop();
		clock.start("书：1234");
		log.info("isbn-1234 -->" + bookRepository.getByIsbn("isbn-1234"));
		clock.stop();
		clock.start("书：4567");
		log.info("isbn-4567 -->" + bookRepository.getByIsbn("isbn-4567"));
		clock.stop();
		clock.start("书：1234");
		log.info("isbn-1234 -->" + bookRepository.getByIsbn("isbn-1234"));
		clock.stop();
		clock.start("书：1234");
		log.info("isbn-1234 -->" + bookRepository.getByIsbn("isbn-1234"));
		log.info("isbn-1234 -->" + bookRepository.getByIsbn(null));
		clock.stop();

		log.info(clock.prettyPrint());
	}
}
